﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Backup.Services.Entities;
using BackupObjects;
using BackupObjects.Taging;
using NUnit.Framework;

namespace Backup.Services.Tests
{
    [TestFixture]
    public class BackupEntityTests
    {
        private static TagRepository _tagRepository;

        private Tag tag1;
        private Tag tag2;

        [SetUp]
        public void TagRepositorySetUp()
        {
            _tagRepository = new TagRepository();

            _tagRepository
                            .LoadAll()
                            .ForEach(item => _tagRepository.Delete(item.Id));

            tag1 = new Tag() { Id = Guid.NewGuid(), Name = "Tag1Name" };
            tag2 = new Tag() { Id = Guid.NewGuid(), Name = "Tag2Name" };

            _tagRepository.Save(tag1);
            _tagRepository.Save(tag2);
        }

        [Test]
        public void BackupObjectToBackupEntityTest()
        {
            BackupObject backupObject = new BackupObject()
                                            {
                                                Description = "Description",
                                                Contents = new byte[] {1, 2, 3},
                                                ID = Guid.NewGuid(),
                                                Name = "Name",
                                                OriginalFileName = "OriginalFileName",
                                                TagIds = {tag1.Id, tag2.Id},
                                                UploadBy = "UploadBy",
                                                UploadDate = DateTime.Now,
                                                Visibility = VisibilityBackup.Private
                                            };

            BackupEntity backupEntity =backupObject;

            Assert.IsNotNull(backupEntity);
            Assert.AreEqual(backupObject.Description,backupEntity.Description);
            Assert.AreEqual(backupObject.ID,backupEntity.Id);
            Assert.AreEqual(backupObject.Name,backupEntity.Name);
            Assert.AreEqual(backupObject.OriginalFileName,backupEntity.OriginalFileName);
            Assert.AreEqual(backupObject.UploadBy,backupEntity.UploadBy);
            Assert.AreEqual(backupObject.UploadDate,backupEntity.UploadDate);
            Assert.AreEqual(backupObject.Visibility,backupEntity.Visibility);

            var tagIds = backupEntity.TagIds;
            foreach (var tagId in backupObject.TagIds)
            {
                Assert.Contains(tagId, tagIds);
            }

        }
    }
}
